package com.example.xd.javatest.socket_test;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @auther XuDan on 2020/7/1.
 */
public class ClientSocket {
    public static void main(String[] args) {
        try {
            send();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void send() throws IOException {
        Socket socket = new Socket("127.0.0.1", 8888);
        OutputStream os = socket.getOutputStream();
        PrintWriter pw = new PrintWriter(os);
        pw.write("你好");
        pw.flush();
        socket.shutdownOutput();//关闭输出流
        socket.close();
    }
}
